<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>发货单管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
        function ajaxs(){
        	$.ajax({
                url:'${ctx}/kdniaocommonpojo/logisticsThreeParty/Verification',
                type:'POST', //GET
                async:false,// 或false,是否异步
                data:{
                    companys: function() {
                        return $("#companys").val();
                    },
                    codes: function() {
                        return $("#codes").val();
                    }
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式
                success:function(data){
                     if(data.Verification!=true && data.Verification!='true')
                        {
                             message=data.Verification;
                        }else{
                            result=data.Verification;
                        }
                }
            });
            }
		$(document).ready(function() {
			//重新写验证方法以满足动态提示语句
			$.validator.addMethod('ajaxmessages', function (value, element) {
				var message='';
			     var result = false;
			     $.ajax({
	                    url:'${ctx}/kdniaocommonpojo/logisticsThreeParty/Verification',
	                    type:'POST', //GET
	                    async:false,// 或false,是否异步
	                    data:{
	                        companys: function() {
	                            return $("#companys").val();
	                        },
	                        codes: function() {
                                return $("#codes").val();
                            }
	                    },
	                    timeout:5000,    //超时时间
	                    dataType:'json',    //返回的数据格式
	                    success:function(data){
	                    	 if(data.Verification!=true && data.Verification!='true')
	                    		{
	                                 message=data.Verification;
	                    		}else{
	                    			result=data.Verification;
			                    }
	                    }
	                });
	                if(message!=''){
	                    $.validator.messages.ajaxmessages = message;
	                 }
			      return result;
			 }); 
			//$("#name").focus();
			$("#inputForm").validate({
				rules:{
					code:{
						required:true,
						ajaxmessages:true
					   },
					company:{
						required:true,
						ajaxmessages:true
                       }
			    },
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/shop/dispatch">发货单列表</a></li>
		<li class="active"><a
			href="${ctx}/shop/dispatch/form?id=${shopDispatch.id}">发货单<shiro:hasPermission
					name="shop:dispatch:edit">${not empty shopDispatch.id?'修改':'添加'}</shiro:hasPermission>
				<shiro:lacksPermission name="shop:dispatch:edit">修改</shiro:lacksPermission></a></li>
	</ul>
	<br />
	<form:form id="inputForm" modelAttribute="shopDispatch"
		action="${ctx}/shop/dispatch/save" method="post"
		class="form-horizontal">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label">订单编号：</label>
			<div class="controls">
				<form:input path="shopOrder.code" htmlEscape="false" maxlength="64"
					class="input-xlarge required" readonly="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">收货人：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false"
					class="input-xlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">联系电话：</label>
			<div class="controls">
				<form:input path="telephone" htmlEscape="false"
					class="input-xlarge " />
			</div>
		</div>  
		<div class="control-group">
            <label class="control-label">收货地址：</label>
            <div class="controls">
                <form:input path="address" htmlEscape="false"
                    class="input-xlarge " />
            </div>
        </div>  
		<div class="control-group">
			<label class="control-label">所选物流：</label>
			<div class="controls">
				<form:select path="company" id="companys" style="width:283px;">
				    <form:option value=""> </form:option>
				    <c:forEach items="${logisticsCodes }" var="logisticsCode">
				        <form:option value="${logisticsCode.logisticsCode }"> ${logisticsCode.logisticsCompany }</form:option>
				    </c:forEach>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
            <label class="control-label">快递单号：</label>
            <div class="controls">
              <form:input path="code" id="codes" htmlEscape="false" maxlength="64" class="input-xlarge " />
                <span class="help-inline"><font color="red">*</font> </span>
            </div>
        </div>
		<div class="control-group">
			<label class="control-label">发货单状态：</label>
			<div class="controls">
				<form:select path="status" style="width:120px;">
					<c:choose>
                  		<c:when test="${shopDispatch.status == '1'}">
                  			<form:option value="1">待发货</form:option>
                  			<form:option value="2">已发货</form:option>
                  		</c:when>
                  		<c:when test="${shopDispatch.status == '2'}">
                  			<form:option value="2">已发货</form:option>
							<form:option value="3">已收货</form:option>
                  		</c:when>
                  		<c:when test="${shopDispatch.status == '3'}">
							<form:option value="3">已收货</form:option>
                  		</c:when>
                  	</c:choose>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:input path="comment" htmlEscape="false" maxlength="255"
					class="input-xlarge " />
			</div>
		</div>

		<div class="form-actions">
            <shiro:hasPermission name="shop:order:manage:edit">
                <input id="btnSubmit" class="btn btn-primary" type="submit"
                    value="保 存" />&nbsp;</shiro:hasPermission>
            <input id="btnCancel" class="btn" type="button" value="返 回"
                onclick="history.go(-1)" />
        </div>

		<!-- 商品列表 -->
		<div style="margin: 20px 20px 20px 20px ;margin-b: 20px; border-bottom: 1px #ccc solid;"></div>
		<div style="text-align:center"><h3>商品列表</h3></div>
		<div class="control-group">
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th>商品名称</th>
						<th>商品货号</th>
						<th>商品单价</th>
						<th>商品数量</th>
						<th>小计</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${shopDispatch.shopOrder.shopOrderInfoList}"
						var="shopDispatchInfo">
						<tr>
							<td>${shopDispatchInfo.name }</td>
							<td>${shopDispatchInfo.code }</td>
							<td>${shopDispatchInfo.price }</td>
							<td>${shopDispatchInfo.count }</td>
							<td>${shopDispatchInfo.totalAmount }</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</form:form>
	
	<div style="margin:20px 20px 20px 20px ;margin-b:20px; border-bottom:1px #ccc solid;"></div>
	<form:form id="inputOperateForm" modelAttribute="shopDispatch"
        action="${ctx}/shop/order/shopOperate/save" method="post"
        class="form-horizontal">
        <!-- 操作信息 -->
        <div style="text-align:center"><h3>操作记录</h3></div>
        <div class="control-group">
            <table class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>操作者</th>
                        <th>操作时间</th>
                        <th>订单状态</th>
                        <th>描述</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${shopDispatch.shopDispatchOperates}"
                        var="shopDispatchOperate">
                        <tr>
                            <td>${shopDispatchOperate.createUser }</td>
                            <td><fmt:formatDate value="${shopDispatchOperate.createTime }" pattern="yyyy-MM-dd hh:mm:ss"/></td>
                            <td>
                            <c:choose>
                              <c:when test="${shopDispatchOperate.status== '1'}">
                                                                                               待发货
							   </c:when>
							   <c:when test="${shopDispatchOperate.status== '2'}">
                                                                                               已发货
                               </c:when>
                               <c:when test="${shopDispatchOperate.status== '3'}">
                                                                                               已收货
                               </c:when>
                            </c:choose>
                            </td>
                            <td>${shopDispatchOperate.describes }</td>
                            <td>${shopDispatchOperate.comment }</td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
    </form:form> 
</body>
</html>